package ch09.shili;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

public class S03 {

    public static void main(String[] args)  {
        //文字输出到文件
        String str = "I love Java!";
        byte[] words = str.getBytes();
        System.out.println(Arrays.toString(words));

        //字节输出流
        OutputStream fos = null;

        try {
            fos = new FileOutputStream("data/test2.txt",true);
//            fos.write(words);
            for (byte word : words){
                System.out.println(word);
                fos.write(word);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("输出完成");
    }
}
